package com.coincalf.task.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.joda.time.DateTime;

import java.math.BigDecimal;
import java.util.stream.Stream;

/**
 * @author qiang
 */
@Data
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class Prices implements java.io.Serializable {

    /**
     * 更新时间
     */
    private long updated;
    /**
     *
     */
    private String symbol;
    /**
     *卖
     */
    BigDecimal bid;
    /**
     *买
     */
    BigDecimal ask;
    /**
     *高
     */
    BigDecimal high;
    /**
     *低
     */
    BigDecimal low;
    /**
     * 价格avg(h +l)
     */
    BigDecimal price;

    public BigDecimal getPrice() {
        return BigDecimal.valueOf(Stream.of(high, low)
                .mapToDouble(BigDecimal::doubleValue).average().getAsDouble());
    }

    @JsonIgnore
    public DateTime getUpdatedDate() {
        return new DateTime(updated);
    }
}
